package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.R
import com.erp.bean.ArticleBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_article_item.view.*

/**
 * Created by Administrator on 2019/3/30/030.
 * 作者：刘洋
 */
class ArticleAdapter(var list : MutableList<ArticleBean>,val context: Context) : BaseAdapter(){
    private val minflater: LayoutInflater = LayoutInflater.from(context)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v: View
        var vh: ViewHolder
        if(convertView==null){
            v=minflater.inflate(R.layout.lv_article_item,null)
            vh=ViewHolder(v)
            v.tag=vh
        }else{
            v=convertView
            vh=v.tag as ViewHolder
        }
        var bean = list[position]
        Myutil.settv(bean.title,vh.TvTitle)
        Myutil.settv(bean.hits,vh.TvHits)
        Myutil.settv(Myutil.getdata(bean.ctime),vh.TvCTime)
        Myutil.settv(Myutil.getdata(bean.uptime),vh.TvUpTime)
        var category = ""
        if(bean.kac_category2!=""){
            category=category+bean.kac_category2+"->"
        }
        if(bean.kac_category1!=""){
            category=category+bean.kac_category1+"->"
        }
        category += bean.kac_category
        Myutil.settv(category,vh.TvCategory)
        return v
    }

    override fun getItem(position: Int): Any {
        return list[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return list.size
    }

    class ViewHolder(v : View){
        var TvTitle = v.TvTitle
        var TvHits = v.TvHits
        var TvCTime = v.TvCTime
        var TvUpTime = v.TvUpTime
        var TvCategory=v.TvCategory
    }
}